#delimit;
clear all;
set more off;

capture log using "12_Compare_Growth_DAF_Figures.log", replace;

/*******************************************************************************************/;
** INPUT: DAF Classification combined with IRS financials; 
** OUTPUT: Comparison Graph; 
** LAST MODIFIED: JAG, 1/30/2022;
** RUN TIME: <1 minute;  													      	
/*******************************************************************************************/;

use "DAF classification clean.dta", clear;
** Adding in the DAF financials;
merge 1:m ein using "Main with additional details.dta";

** NOTE: the key visualization is that the growth in DAFs is coming from innovative ones;
sum contrib_all, d;
sum contr_gr, d;
gen ratio=contrib_noncash/contrib_all;
sum ratio, d;
local p50=r(p50);
gen high_noncash=1 if ratio>`p50' & ratio!=.;
bys ein: egen mhigh_noncash=max(high_noncash);
gen takes_noncash=1 if contrib_noncash>0 & contrib_noncash!=.;

**Generate appropriate variables for collapse**;
gen sca_trad=contrib_all if style_trad==1;
gen sca_innov=contrib_all if style_innov==1;
gen sca_disr=contrib_all if style_disrupt==1;
gen sca_nostyle=contrib_all if style_disrupt==0&style_trad==0&style_innov==0;
gen sca_dei=contrib_all if focus_dei==1;
gen sca_tools=contrib_all if feature_tool==1;
gen sca_ntl=contrib_all if is_national==1;
gen sca_lcl=contrib_all if is_national==0;
gen sca_takes_noncash=contrib_all if takes_noncash==1;
gen sca_high_noncash=contrib_all if mhigh_noncash==1;

** Collapsing to get totals and means;
collapse (sum) contrib_all  sca_*, by (year);
gen bcontrib_all=contrib_all if year==2013;
egen mcontrib_all=max(bcontrib_all); 
gen pct_trad=(sca_trad/mcontrib_all)*100;
gen pct_innov=(sca_innov/mcontrib_all)*100;
gen pct_disr=(sca_disr/mcontrib_all)*100;
gen pct_nostyle=(sca_nostyle/mcontrib_all)*100;
gen pct_tools=(sca_tools/mcontrib_all)*100;
gen pct_dei=(sca_dei/mcontrib_all)*100;
gen pct_takes_noncash=(sca_takes_noncash/mcontrib_all)*100;
gen pct_high_noncash=(sca_high_noncash/mcontrib_all)*100;

*Contributions by style of DAF;
graph bar pct_trad pct_nostyle pct_innov pct_disr, over(year) 
bar(1, fcolor(maroon) fintensity(inten60) lcolor(maroon))
bar(2, fcolor(gray) fintensity(inten40) lcolor(gray)) 
bar(3, fcolor(navy) fintensity(inten60) lcolor(navy)) 
bar(4, fcolor(navy) fintensity(inten90) lcolor(navy)) stack
legend(order(1 "Traditional" 2 "No style" 3 "Innovative" 4 "Disruptive"))
ytitle(Contributions (%) 2013 is baseline)
title(Style of services offered)
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
saving("Figures/DAFcontrib_pct_fig", replace);
graph use "Figures/DAFcontrib_pct_fig.gph";
graph export "Figures/DAFcontrib_pct_fig.pdf", replace;

*Contributions relative to other features;
graph bar pct_tools pct_dei pct_high_noncash, over(year) 
bar(1, fcolor(navy) fintensity(inten80) lcolor(navy))
bar(2, fcolor(emerald) fintensity(inten80) lcolor(emerald)) 
bar(3, fcolor(maroon) fintensity(inten80) lcolor(maroon)) 
legend(order(1 "Access to FinTech tools" 2 "DE&I grant making focus     " 3 "Above median non-cash ratio"))
ytitle(Contributions (%) 2013 is baseline)
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white))
saving("Figures/DAFcontrib_pct_fig_other_features", replace);
graph use "Figures/DAFcontrib_pct_fig_other_features.gph";
graph export "Figures/DAFcontrib_pct_fig_other_features.pdf", replace;

log close;
